package com.ruoyi.limitCoupon.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.check.CheckEmptyUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.limitCoupon.domain.LimitCouponMatchesConfig;
import com.ruoyi.limitCoupon.service.ILimitCouponMatchesConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * 限时卡券场次Controller
 * 
 * @author ruoyi
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/limitCouponMatchesConfig/limitCouponMatchesConfig")
public class LimitCouponMatchesConfigController extends BaseController
{
    @Autowired
    private ILimitCouponMatchesConfigService limitCouponMatchesConfigService;

    /**
     * 查询限时卡券场次列表
     */
    @PreAuthorize("@ss.hasPermi('limitCouponMatchesConfig:limitCouponMatchesConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(LimitCouponMatchesConfig limitCouponMatchesConfig)
    {
        startPage();
        List<LimitCouponMatchesConfig> list = limitCouponMatchesConfigService.selectLimitCouponMatchesConfigList(limitCouponMatchesConfig);
        if (!CheckEmptyUtil.isEmpty(list)) {
            for (LimitCouponMatchesConfig couponMatchesConfig : list) {
                couponMatchesConfig.setSnappedTimeVar(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(couponMatchesConfig.getSnappedTime()));
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出限时卡券场次列表
     */
    @PreAuthorize("@ss.hasPermi('limitCouponMatchesConfig:limitCouponMatchesConfig:export')")
    @Log(title = "限时卡券场次", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LimitCouponMatchesConfig limitCouponMatchesConfig)
    {
        List<LimitCouponMatchesConfig> list = limitCouponMatchesConfigService.selectLimitCouponMatchesConfigList(limitCouponMatchesConfig);
        if (!CheckEmptyUtil.isEmpty(list)) {
            for (LimitCouponMatchesConfig couponMatchesConfig : list) {
                couponMatchesConfig.setSnappedTimeVar(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(couponMatchesConfig.getSnappedTime()));
            }
        }
        ExcelUtil<LimitCouponMatchesConfig> util = new ExcelUtil<LimitCouponMatchesConfig>(LimitCouponMatchesConfig.class);
        util.exportExcel(response, list, "限时卡券场次数据");
    }

    /**
     * 获取限时卡券场次详细信息
     */
    @PreAuthorize("@ss.hasPermi('limitCouponMatchesConfig:limitCouponMatchesConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(limitCouponMatchesConfigService.selectLimitCouponMatchesConfigById(id));
    }

    /**
     * 新增限时卡券场次
     */
    @PreAuthorize("@ss.hasPermi('limitCouponMatchesConfig:limitCouponMatchesConfig:add')")
    @Log(title = "限时卡券场次", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LimitCouponMatchesConfig limitCouponMatchesConfig) throws ParseException {
        return toAjax(limitCouponMatchesConfigService.insertLimitCouponMatchesConfig(limitCouponMatchesConfig));
    }

    /**
     * 修改限时卡券场次
     */
    @PreAuthorize("@ss.hasPermi('limitCouponMatchesConfig:limitCouponMatchesConfig:edit')")
    @Log(title = "限时卡券场次", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LimitCouponMatchesConfig limitCouponMatchesConfig) throws ParseException {
        return toAjax(limitCouponMatchesConfigService.updateLimitCouponMatchesConfig(limitCouponMatchesConfig));
    }

    /**
     * 删除限时卡券场次
     */
    @PreAuthorize("@ss.hasPermi('limitCouponMatchesConfig:limitCouponMatchesConfig:remove')")
    @Log(title = "限时卡券场次", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(limitCouponMatchesConfigService.deleteLimitCouponMatchesConfigByIds(ids));
    }
}
